package com.gsq.learning.mybatisplugin.dao;

import com.gsq.learning.mybatisplugin.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @author guishangquan
 * @date 2018/8/23
 */
@Mapper
@CacheNamespace
public interface UserDao {

    @Select("select * from user where name=#{name}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "age", column = "age"),
            @Result(property = "name", column = "name"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "amount", column = "amount")
    })
    User findByName(@Param("name") String name);

    @Select("select * from user where name=#{name} and age=#{age}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "age", column = "age"),
            @Result(property = "name", column = "name"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "amount", column = "amount")
    })
    User findByNameAndAge(@Param("name") String name, @Param("age") Integer age);

    @Select("select * from user")
    List<User> findAll();

    @Insert(" insert into user(age, name, birthday, amount) " +
            " values (#{user.age}, #{user.name}, #{user.birthday}, #{user.amount}) ")
    int insert(@Param("user") User user);

    @Update("update user set age = #{age} where id = #{id}")
    int update(@Param("id") Long id, @Param("age") Integer age);
}
